// smartPtr.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

struct Object{
	
	Object(){
		cout << "Object" << endl;
	}
	~Object(){
		cout << "~Object" << endl;
	}
	void foo(){
		cout << "foo()" << endl;
	}

};

class auto_ptr{
	
	Object *p;

public:
	auto_ptr(Object* ob = 0){
		p = ob;			
	}

	auto_ptr(auto_ptr& b){
		operator=(b);	
	}

	auto_ptr& operator=(auto_ptr& b){
		
		if(&b == this)
			return *this;

		p = b.p;
		b.p = 0;		
		return *this;
	}

	bool isNull(){		
		return p == 0;
	}

	~auto_ptr(){
		if(!isNull()){
			delete p;
		}
	}

	Object& operator*()const{
		return *p;
	}

	Object* operator->(){
		return p;
	}



};


void getFun(auto_ptr p){
	p -> foo();
	p = p;
	//auto_ptr p2(p);
}

void genFun(){
	auto_ptr apt(new Object());	
	apt -> foo();
	getFun(apt);
}

int main(){
	
	genFun();

	int iiii = 0;
	cin >> iiii;
	return 0;
}

